<?php

declare (strict_types=1);
/**
 * @copyright 深圳市易果网络科技有限公司
 * @version 1.0.0
 * @link https://dayiguo.com
 */

namespace App\Controller\user;

use App\Dao\GoodsDao;
use App\Dao\UserFavDao;
use App\Middleware\User\UserMiddleware;

use App\Service\User\IntegralDetailService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\HttpServer\Annotation\Middleware;

/**
 * 积分明细
 *
 * @Middleware(UserMiddleware::class)
 * @AutoController()
 * @author 张昊(2396675557@qq.com)
 * @package App\Controller\user
 */
class IntegralController extends Controller
{

    /**
     * @Inject
     * @var IntegralDetailService
     */
    private $integral_service;

    /**
     * 刷新积分
     */
    public function refresh()
    {
        $user_id = (int)$this->request->input('user_id', 0);

        $this->integral_service->updateIntegralBalance( $user_id );

        $this->success();
    }


    /**
     * 用户积分明细 --- 分润获得
     */
    public function userIntegral()
    {
        $result = $this->integral_service->get();

        return $result ? $this->success($result) : $this->error();
    }

}